using ns0;
using System;
using System.Windows;
using System.Windows.Media.Imaging;
public class RGBLuminanceSource : LuminanceSource
{
	private sbyte[] sbyte_0;
	private bool bool_0 = false;
	private bool bool_1 = false;
	private Rect rect_0;
	private int int_2;
	private int int_3;
	public override int Height
	{
		get
		{
			int result;
			if (!this.bool_0)
			{
				result = this.int_2;
			}
			else
			{
				result = this.int_3;
			}
			return result;
		}
	}
	public override int Width
	{
		get
		{
			int result;
			if (!this.bool_0)
			{
				result = this.int_3;
			}
			else
			{
				result = this.int_2;
			}
			return result;
		}
	}
	public override sbyte[] Matrix
	{
		get
		{
			return this.sbyte_0;
		}
	}
	public override bool RotateSupported
	{
		get
		{
			return true;
		}
	}
	public RGBLuminanceSource(byte[] byte_0, int W, int H) : base(W, H)
	{
		this.int_3 = W;
		this.int_2 = H;
		this.sbyte_0 = new sbyte[W * H];
		for (int i = 0; i < H; i++)
		{
			int num = i * W;
			for (int j = 0; j < W; j++)
			{
				int num2 = (int)byte_0[num * 3 + j * 3];
				int num3 = (int)byte_0[num * 3 + j * 3 + 1];
				int num4 = (int)byte_0[num * 3 + j * 3 + 2];
				if (num2 == num3 && num3 == num4)
				{
					this.sbyte_0[num + j] = (sbyte)num2;
				}
				else
				{
					this.sbyte_0[num + j] = (sbyte)(num2 + num3 + num3 + num4 >> 2);
				}
			}
		}
	}
	public RGBLuminanceSource(byte[] byte_0, int W, int H, bool Is8Bit) : base(W, H)
	{
		this.int_3 = W;
		this.int_2 = H;
		this.sbyte_0 = new sbyte[W * H];
		Buffer.BlockCopy(byte_0, 0, this.sbyte_0, 0, W * H);
	}
	public RGBLuminanceSource(byte[] byte_0, int W, int H, bool Is8Bit, Rect Region) : base(W, H)
	{
		this.int_3 = (int)Region.get_Width();
		this.int_2 = (int)Region.get_Height();
		this.rect_0 = Region;
		this.bool_1 = true;
	}
	public RGBLuminanceSource(WriteableBitmap writeableBitmap_0, int W, int H) : base(W, H)
	{
		this.int_3 = W;
		this.int_2 = H;
		this.sbyte_0 = new sbyte[W * H];
		for (int i = 0; i < H; i++)
		{
			int num = i * W;
			for (int j = 0; j < W; j++)
			{
				int num2 = writeableBitmap_0.get_Pixels()[j + W * i];
				this.sbyte_0[num + j] = (sbyte)((num2 >> 16 & 255) << 16 | (num2 >> 8 & 255) << 8 | (num2 & 255));
			}
		}
	}
	public override sbyte[] getRow(int int_4, sbyte[] sbyte_1)
	{
		sbyte[] result;
		if (!this.bool_0)
		{
			int width = this.Width;
			if (sbyte_1 == null || sbyte_1.Length < width)
			{
				sbyte_1 = new sbyte[width];
			}
			for (int i = 0; i < width; i++)
			{
				sbyte_1[i] = this.sbyte_0[int_4 * width + i];
			}
			result = sbyte_1;
		}
		else
		{
			int width = this.int_3;
			int num = this.int_2;
			if (sbyte_1 == null || sbyte_1.Length < num)
			{
				sbyte_1 = new sbyte[num];
			}
			for (int i = 0; i < num; i++)
			{
				sbyte_1[i] = this.sbyte_0[i * width + int_4];
			}
			result = sbyte_1;
		}
		return result;
	}
	public override LuminanceSource crop(int left, int int_4, int width, int height)
	{
		return base.crop(left, int_4, width, height);
	}
	public override LuminanceSource rotateCounterClockwise()
	{
		this.bool_0 = true;
		return this;
	}
}
